//
//  HomeScrollView.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 2017/12/13.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "HomeScrollView.h"
@interface HomeScrollView ()
@property (nonatomic, strong)UIView *firstView1;
@property (nonatomic, strong)UIView *firstView2;
@property (nonatomic, strong)UIView *secondView1;
@property (nonatomic, strong)UIView *secondView2;
@property (nonatomic, strong)UIImageView *logOutView;
@property (nonatomic, strong)UILabel *logOutTipLabel;
@property (nonatomic, strong)UILabel *bindingLabel;
@property (nonatomic, strong)UILabel *carTypeLabel;
@property (nonatomic, strong)UILabel *carNumLabel;
@property (nonatomic, strong)UILabel *waterLabel;
@property (nonatomic, strong)UILabel *oilPressureLabel;
@property (nonatomic, strong)UILabel *dateLabel;
@property (nonatomic, strong)UIImageView *developView;
@property (nonatomic, strong)UILabel *developLabel;
@property (nonatomic, strong)UILabel *comingsoon;
@property (nonatomic, strong)ImageTextView *btnView1;
@property (nonatomic, strong)ImageTextView *btnView2;
@property (nonatomic, strong)ImageTextView *btnView3;
@property (nonatomic, strong)ImageTextView *btnView4;
@end

@implementation HomeScrollView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = Color.back;
        self.contentSize = CGSizeMake(self.frame.size.width*2, self.frame.size.height);
        self.contentOffset = CGPointMake(0, 0);
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = YES;
        self.pagingEnabled = YES;
        self.bounces = NO;
        self.showsHorizontalScrollIndicator = NO;
        //第一个界面上部分
        self.firstView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 204)];
        self.firstView1.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.firstView1];
        //第一个界面下部分
        self.firstView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 214, self.frame.size.width, 110)];
        self.firstView2.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.firstView2];
        //第二个界面上部分
        self.secondView1 = [[UIView alloc]initWithFrame:CGRectMake(self.frame.size.width, 0, self.frame.size.width, 204)];
        self.secondView1.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.secondView1];
        //第二个界面下部分
        self.secondView2 = [[UIView alloc]initWithFrame:CGRectMake(self.frame.size.width, 214, self.frame.size.width, 110)];
        self.secondView2.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.secondView2];
        
        self.dateLabel.hidden = YES;
        self.oilPressureLabel.hidden = YES;
        self.waterLabel.hidden = YES;
        self.carNumLabel.hidden = YES;
        self.carTypeLabel.hidden = YES;
        self.logOutView.hidden = YES;
        self.logOutTipLabel.hidden = YES;
        self.bindingLabel.hidden = YES;
        
        self.dateLabel.text = @"下次年检日期：2019年11月10日";
        self.oilPressureLabel.text = @"油压：0.3MPa";
        self.waterLabel.text = @"水温：27℃";
        self.carNumLabel.text = @"车牌号：苏D123456789";
        self.carTypeLabel.text = @"车类型：奥迪";
    }
    return self;
}

-(void)layoutSubviews{
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(self.firstView1.mas_bottom).offset(-15);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-15);
        make.leading.mas_equalTo(self.firstView1.mas_leading).offset(15);
    }];
    [self.oilPressureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(self.dateLabel.mas_top).offset(-15);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-15);
        make.leading.mas_equalTo(self.firstView1.mas_leading).offset(15);
    }];
    [self.waterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(self.oilPressureLabel.mas_top).offset(-15);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-15);
        make.leading.mas_equalTo(self.firstView1.mas_leading).offset(15);
    }];
    [self.carNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(self.waterLabel.mas_top).offset(-15);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-15);
        make.leading.mas_equalTo(self.firstView1.mas_leading).offset(15);
    }];
    [self.carTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(15);
        make.bottom.mas_equalTo(self.carNumLabel.mas_top).offset(-15);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-15);
        make.leading.mas_equalTo(self.firstView1.mas_leading).offset(15);
    }];
    
    [self.logOutView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.firstView1.mas_centerY);
        make.trailing.mas_equalTo(self.firstView1.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(98, 101));
    }];
    [self.logOutTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(18);
        make.leading.mas_equalTo(self.logOutView.mas_trailing);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-55);
        make.bottom.mas_equalTo(self.firstView1.mas_centerY);
    }];
    [self.bindingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(80);
        make.trailing.mas_equalTo(self.firstView1.mas_trailing).offset(-55);
        make.top.mas_equalTo(self.firstView1.mas_centerY).offset(20);
    }];
    
    [self.btnView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.firstView2.mas_leading);
        make.width.mas_equalTo(self.frame.size.width/4);
        make.bottom.mas_equalTo(self.firstView2.mas_bottom);
        make.top.mas_equalTo(self.firstView2.mas_top);
    }];
    [self.btnView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.btnView1.mas_trailing);
        make.width.mas_equalTo(self.frame.size.width/4);
        make.bottom.mas_equalTo(self.firstView2.mas_bottom);
        make.top.mas_equalTo(self.firstView2.mas_top);
    }];
    [self.btnView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.btnView2.mas_trailing);
        make.width.mas_equalTo(self.frame.size.width/4);
        make.bottom.mas_equalTo(self.firstView2.mas_bottom);
        make.top.mas_equalTo(self.firstView2.mas_top);
    }];
    [self.btnView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.btnView3.mas_trailing);
        make.width.mas_equalTo(self.frame.size.width/4);
        make.bottom.mas_equalTo(self.firstView2.mas_bottom);
        make.top.mas_equalTo(self.firstView2.mas_top);
    }];
    [self.comingsoon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.secondView2.mas_top);
        make.leading.mas_equalTo(self.secondView2.mas_leading);
        make.trailing.mas_equalTo(self.secondView2.mas_trailing);
        make.bottom.mas_equalTo(self.secondView2.mas_bottom);
    }];
    [self.developView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.secondView1.mas_top).offset(25);
        make.centerX.mas_equalTo(self.secondView1.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(138, 101));
    }];
    [self.developLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.developView.mas_bottom).offset(25);
        make.leading.mas_equalTo(self.secondView1.mas_leading);
        make.trailing.mas_equalTo(self.secondView1.mas_trailing);
        make.bottom.mas_equalTo(self.secondView1.bottom).offset(-37.5);
    }];
}

-(void)setIsLogin:(BOOL)isLogin{
    self.dateLabel.hidden = !isLogin;
    self.oilPressureLabel.hidden = !isLogin;
    self.waterLabel.hidden = !isLogin;
    self.carNumLabel.hidden = !isLogin;
    self.carTypeLabel.hidden = !isLogin;
    self.logOutView.hidden = isLogin;
    self.logOutTipLabel.hidden = isLogin;
    self.bindingLabel.hidden = isLogin;
}

#pragma mark ----- 未绑定视图 -----
-(UIImageView *)logOutView{
    if (!_logOutView) {
        _logOutView = [[UIImageView alloc]init];
        _logOutView.image = [UIImage imageNamed:@"sy_weibangdin"];
        [self addSubview:_logOutView];
    }
    return _logOutView;
}

#pragma mark ----- 您未绑定设备 -----
-(UILabel *)logOutTipLabel{
    if (!_logOutTipLabel) {
        _logOutTipLabel = [[UILabel alloc]init];
        [self addSubview:_logOutTipLabel];
        [self CreatNewLabel:_logOutTipLabel title:@"您未绑定设备" color:Color.theme font:Common_Font(15)];
        _logOutTipLabel.textAlignment = NSTextAlignmentRight;
    }
    return _logOutTipLabel;
}

#pragma mark ----- 车类型 -----
-(UILabel *)carTypeLabel{
    if (!_carTypeLabel) {
        _carTypeLabel = [[UILabel alloc]init];
        [self addSubview:_carTypeLabel];
        [self CreatNewLabel:_carTypeLabel title:@"" color:UIColorFromRGB(0x262626) font:Common_Font(15)];
        _carTypeLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _carTypeLabel;
}

#pragma mark ----- 车牌号 -----
-(UILabel *)carNumLabel{
    if (!_carNumLabel) {
        _carNumLabel = [[UILabel alloc]init];
        [self addSubview:_carNumLabel];
        [self CreatNewLabel:_carNumLabel title:@"" color:UIColorFromRGB(0x262626) font:Common_Font(15)];
        _carNumLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _carNumLabel;
}

#pragma mark ----- 水温 -----
-(UILabel *)waterLabel{
    if (!_waterLabel) {
        _waterLabel = [[UILabel alloc]init];
        [self addSubview:_waterLabel];
        [self CreatNewLabel:_waterLabel title:@"" color:UIColorFromRGB(0x262626) font:Common_Font(15)];
        _waterLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _waterLabel;
}

#pragma mark ----- 油压 -----
-(UILabel *)oilPressureLabel{
    if (!_oilPressureLabel) {
        _oilPressureLabel = [[UILabel alloc]init];
        [self addSubview:_oilPressureLabel];
        [self CreatNewLabel:_oilPressureLabel title:@"" color:UIColorFromRGB(0x262626) font:Common_Font(15)];
        _oilPressureLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _oilPressureLabel;
}

#pragma mark ----- 年检 -----
-(UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc]init];
        [self addSubview:_dateLabel];
        [self CreatNewLabel:_dateLabel title:@"" color:UIColorFromRGB(0x262626) font:Common_Font(15)];
        _dateLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _dateLabel;
}

#pragma mark -----现在绑定 -----
-(UILabel *)bindingLabel{
    if (!_bindingLabel) {
        _bindingLabel = [[UILabel alloc]init];
        [self addSubview:_bindingLabel];
        [self CreatNewLabel:_bindingLabel title:@"现在绑定" color:Color.selected_blue font:Common_Font(16)];
        _bindingLabel.textAlignment = NSTextAlignmentRight;
    }
    return _bindingLabel;
}

#pragma mark ----- 开发中图片 -----
-(UIImageView *)developView{
    if (!_developView) {
        _developView = [[UIImageView alloc]init];
        _developView.image = [UIImage imageNamed:@"kaifazhong"];
        [self addSubview:_developView];
    }
    return _developView;
}

#pragma mark ----- 项目开发中 -----
-(UILabel *)developLabel{
    if (!_developLabel) {
        _developLabel = [[UILabel alloc]init];
        [self addSubview:_developLabel];
        [self CreatNewLabel:_developLabel title:@"项目开发中~~" color:Color.theme font:Common_Font(15)];
    }
    return _developLabel;
}

#pragma mark ----- 敬请期待 -----
-(UILabel *)comingsoon{
    if (!_comingsoon) {
        _comingsoon = [[UILabel alloc]init];
        [self addSubview:_comingsoon];
        [self CreatNewLabel:_comingsoon title:@"敬请期待！" color:Color.theme font:Common_Font(18)];
    }
    return _comingsoon;
}

#pragma mark ----- 锁车解锁 -----
-(ImageTextView *)btnView1{
    if (!_btnView1) {
        _btnView1 = [[ImageTextView alloc]init];
        _btnView1.titleLabel.text = @"锁车";
        _btnView1.titleView.image = [UIImage imageNamed:@"yuyin_suoche"];
        [self addSubview:_btnView1];
    }
    return _btnView1;
}

#pragma mark ----- 启动关闭 -----
-(ImageTextView *)btnView2{
    if (!_btnView2) {
        _btnView2 = [[ImageTextView alloc]init];
        _btnView2.titleLabel.text = @"启动";
        _btnView2.titleView.image = [UIImage imageNamed:@"yuyin_qidon"];
        [self addSubview:_btnView2];
    }
    return _btnView2;
}

#pragma mark ----- 开窗关窗 -----
-(ImageTextView *)btnView3{
    if (!_btnView3) {
        _btnView3 = [[ImageTextView alloc]init];
        _btnView3.titleLabel.text = @"关窗";
        _btnView3.titleView.image = [UIImage imageNamed:@"yuyin_guanchuang"];
        [self addSubview:_btnView3];
    }
    return _btnView3;
}

#pragma mark ----- 通风 -----
-(ImageTextView *)btnView4{
    if (!_btnView4) {
        _btnView4 = [[ImageTextView alloc]init];
        _btnView4.titleLabel.text = @"通风";
        _btnView4.titleView.image = [UIImage imageNamed:@"yuyin_tongfeng"];
        [self addSubview:_btnView4];
    }
    return _btnView4;
}

-(void)CreatNewLabel:(UILabel *)label title:(NSString *)title color:(UIColor *)color font :(UIFont *)font{
    label.text = title;
    label.userInteractionEnabled = YES;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = color;
    label.font = font;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end

@implementation ImageTextView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(26);
            make.centerX.mas_equalTo(self.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(22, 26));
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(18);
            make.leading.mas_equalTo(self.mas_leading);
            make.trailing.mas_equalTo(self.mas_trailing);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-26);
        }];
    }
    return self;
}

#pragma mark ----- 开发中图片 -----
-(UIImageView *)titleView{
    if (!_titleView) {
        _titleView = [[UIImageView alloc]init];
        [self addSubview:_titleView];
    }
    return _titleView;
}

#pragma mark ----- 内容标签----
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        [self addSubview:_titleLabel];
        [self CreatNewLabel:_titleLabel color:UIColorFromRGB(0x262626) font:Common_Font(18)];
    }
    return _titleLabel;
}

-(void)CreatNewLabel:(UILabel *)label color:(UIColor *)color font :(UIFont *)font{
    label.userInteractionEnabled = YES;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = color;
    label.font = font;
}
@end
